package iot.ht.controller.htmenu;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import iot.core.annotation.Auth;
import iot.core.annotation.Log;
import iot.core.data.TreeViewNode;
import iot.core.data.BaseQto;
import iot.core.enums.AuthType;
import iot.core.manager.auth.AuthManager;
import iot.ht.controller.htmenu.data.HTMenuDto;
import iot.ht.controller.htmenu.data.HTMenuInsertQto;
import iot.ht.controller.htmenu.service.IHTMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/htmenu")
@Tag(name = "菜单管理", description = "")
public class HTMenuController {
    @Autowired
    IHTMenuService ihtMenuService;

    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/insertinit")
    @Operation(summary = "插入菜单初始化", description = "")
    public HTMenuDto insertInit(@RequestBody HTMenuInsertQto mm )   {
         return  ihtMenuService.InsertInit(mm);
    }


    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/detail")
    @Operation(summary = "菜单详情", description = "")
    public HTMenuDto detail(@RequestBody BaseQto mm){
        return ihtMenuService.Detail(mm);
    }

    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/insert")
    @Operation(summary = "新增菜单", description = "")
    public  int Insert(@RequestBody HTMenuDto mm){
        return ihtMenuService.Insert(mm);
    }


    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/update")
    @Operation(summary = "修改菜单", description = "")
    public  int Update(@RequestBody HTMenuDto mm){
        return ihtMenuService.Update(mm);
    }


    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/delete")
    @Operation(summary = "删除菜单", description = "")
    public  int Delete(@RequestBody BaseQto mm){
        return ihtMenuService.delete(mm);
    }


    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/gettree")
    @Operation(summary = "功能菜单分页", description = "")
    public List<TreeViewNode> getTree(@RequestBody BaseQto mm){
        return AuthManager.getInstance().getMenuByHTPlatIdAsync(mm.getId() );
    }





}
